 <!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>{$Think.config.site.title} - 商户管理</title>

    <meta name="keywords" content="{$Think.config.site.keywords}">

    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">

</head>
<style>
#listtable .fa{
	cursor:pointer;
	color:#1ab394;
	margin-right:1em;
}
th .tag{font-size: 12px; color: #e66c6c; font-weight: normal;}
.ibox-title .tag{font-size: 12px; color: #e66c6c; font-weight: normal; display: inline-block; margin-left: 20px;}
.specval-hide{display: none;}
th,td{text-align: center;}
.select_sort{cursor: pointer;}

.text-l{text-align: left;}

.quciksubmit{padding: 2px 10px;}
</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-4">
                <div id="nestable-menu">
                    <button type="button" class="btn btn-white btn-sm addshop">添加商户</button>
                    <button type="button" class="btn btn-primary btn-sm uplevel">升为VIP用户</button>
                    <button type="button" class="btn btn-white btn-sm downlevel">降为普通用户</button>
                </div>
            </div>
        </div>
		
      <div class="row">
          <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>商户列表</h5>
                        <!-- <span class="tag">说明：</span> -->
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                        	<div class="col-sm-6">
                        	</div>
                          	<div class="col-sm-6">
                                <div class="input-group pull-right">
									<form id="froms" name="myform" action="{:url('index')}" method="get" enctype="application/x-www-form-urlencoded">
                                        <div class="input-group pull-right">
                                            <input type="text" placeholder="请输入关键词" class="input-sm form-control" value="{$Think.get.keywords ?? ''}" name="keywords">
                                            <input type="hidden" class="sort" name="sort" value="">
                                            <input type="hidden" class="sort_status" name="sort_status" value="">
                                            <span class="input-group-btn">
                                                <button type="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
                                        </div>

										<div class="input-group  pull-right">
                                            <select class="form-control input-sm quciksubmit" name="emp_id">
                                                <option value="">请选择管家...</option>
                                                <option value="-1" {eq name="emp_id" value="-1"}selected="selected"{/eq}>未分配</option>
                                                {volist name="employee" id="vo"}
                                                    <option value="{$vo.id}" {eq name="emp_id" value="$vo.id"}selected="selected"{/eq}>{$vo.name}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                        <div class="input-group  pull-right">
                                            <select class="form-control input-sm quciksubmit" name="sc_id">
                                                <option value="">请选择类型...</option>
                                                {volist name="cate" id="vo"}
                                                    <option value="{$vo.sc_id}" {eq name="sc_id" value="$vo.sc_id"} selected="selected" {/eq}>{$vo.sc_name}</option>
                                                {/volist}
                                            </select>
                                        </div>
									</form>
                                </div>
                            </div>
                            
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped" id="listtable">
                                <thead>
                                    <tr>
                                        <th width="30"><input name="checkall" id="checkall"  type="checkbox" class="i-checks" value="1"></th>
                                        <!-- <th width="100" class="select_sort" data-select_sort='shop_id ' data-sort="{$sort_status}">ID <span>↕</span></th> -->
                                        <th width="100">头像</th>
                                        <th width="200" class="text-l">昵称</th>

                                        <th class="text-l">商户名称</th>
                                        <th width="150" class="text-l">商户类型</th>
                                        <th width="150" class="text-l">商户等级</th>
                                        <th width="150" class="text-l">管家</th>
                                        <th width="100" class="select_sort" data-select_sort='create_time ' data-sort="{$sort_status}">注册时间 <span>↕</span></th>
                                        <th width="100" class="select_sort" data-select_sort='order_nums ' data-sort="{$sort_status}">成交订单数 <span>↕</span></th>
                                        <th width="100" class="select_sort" data-select_sort='money ' data-sort="{$sort_status}">成交金额 <span>↕</span></th>
                                        <th width="150">操作</th>
                                    </tr>
                                </thead>
                                <tbody>

                                	{volist name="list" id="vo"}
                                    <tr data-id="{$vo.shop_id}" data-user_id='{$vo.user_id}'>
                                        <td>
                                            <input name="ids[]"  type="checkbox" class="i-checks" value="{$vo.shop_id}">
                                        </td>
                                        <!-- <td>{$vo.shop_id}</td> -->
                                        <td><img src="{$vo.avatar}" width="50" height="50" /></td>
                                        <td class="text-l">{$vo.nickname}<br />{$vo.phone}</td>

                                        <td class="text-l">名称：{$vo.shop_name}<br/>负责人：{$vo.shop_owner}<br/>地址：{$vo.shop_province}{$vo.shop_city}{$vo.shop_district}{$vo.shop_address}</td>
                                        <td class="text-l">{$vo.sc_name}</td>
                                        <td class="text-l">{$vo.level_name}</td>
                                        <td class="text-l">{$vo.name ? : '待分配'}<br />{$vo.ephone}</td>

                                        <td>{:date('Y-m-d',strtotime($vo['create_time']))}</td>
                                        <td>{$vo.order_nums}</td>
                                        <td>{gt name="$vo.money" value="0"}{$vo.money}{else/}--{/gt}</td>
                                        <td>
                                        	<i class="fa fa-edit allot"> 分配管家</i>
                                            <i class="fa fa-edit edit"> 修改</i>
                                        </td>
                                    </tr>
                                   {/volist}
                                </tbody>
                            </table>
                        </div>
                        <div>{$list->render()}</div>
                    </div>
                </div>
            </div>

        </div>
    </div>

    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/peity/jquery.peity.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
    <script src="{$Think.config.site.common_resource_url}js/majax.js"></script>
    <script src="{$Think.config.site.common_resource_url}js/jedit.js"></script>
</body>

</html>
<script>

var layer_font='';
var $editTr;
$(document).ready(function() {
	
	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

	//全选
	$("#checkall").bind("ifChecked",function(){
		$("input[name='ids[]']").iCheck("check");
	});
	//取消全选
	$("#checkall").bind("ifUnchecked",function(){
		$("input[name='ids[]']").iCheck("uncheck");
	});
	//顶部按钮
    $("#nestable-menu").on("click",
    function(e) {
        var target = $(e.target),
        action = target.data("action");

    });
});	

$('.uplevel').click(function(){
    var list = [];
    $('input[name="ids[]"]:checked').each(function(){
        list.push($(this).val());
    })
    if (list.length==0) {
        layer.msg('至少选择一项',{icon:2});
        return false;
    }

    majax('{:url("uplevel")}',{ids:list.join(',')},function(re){
        if (re.code==0) {
            layer.msg(re.msg);
        }
    })
})

$('.downlevel').click(function(){
    var list = [];
    $('input[name="ids[]"]:checked').each(function(){
        list.push($(this).val());
    })
    if (list.length==0) {
        layer.msg('至少选择一项',{icon:2});
        return false;
    }
    majax('{:url("downlevel")}',{ids:list.join(',')},function(re){
        if (re.code==0) {
            layer.msg(re.msg);
        }
    })
})

$('.addshop').click(function(){
    layer_font = layer.open({
        type: 2,
        title: '添加商户',
        shadeClose: true,
        shade: 0.8,
        area: ['900px', '90%'],
        content: '{:url("addshop")}', //iframe的url
        btn: ['确定', '取消'],
        btn1: function(index, layero){
            var d = $('iframe',layero)[0].contentDocument;
            var uid = $("input[name='uid']:checked",d).val();
            if(uid == undefined) {
                layer.msg('未选择管家', {icon: 2});
                layer.close(index);
                return false;
            }
            majax('{:url("allot")}',{uid:uid,ids:id},function(d){
                if (d.code<=0) {
                    layer.msg(d.msg, {icon: 5});
                    layer.close(index);
                }
            })
        }
    });
})
function editsuccess(){
    layer.close(layer_font);
    window.location.reload(true);
}


$('.allot').click(function(){
	var id = $(this).closest('tr').data('id');
    layer_font = layer.open({
        type: 2,
        title: '选择管家',
        shadeClose: true,
        shade: 0.8,
        area: ['900px', '90%'],
        content: '{:url("allot")}', //iframe的url
        btn: ['确定', '取消'],
        btn1: function(index, layero){
            var d = $('iframe',layero)[0].contentDocument;
            var uid = $("input[name='uid']:checked",d).val();
            if(uid == undefined) {
                layer.msg('未选择管家', {icon: 2});
                layer.close(index);
                return false;
            }
            majax('{:url("allot")}',{uid:uid,ids:id},function(d){
                if (d.code<=0) {
                    layer.msg(d.msg, {icon: 5});
                    layer.close(index);
                }
            })
        }
    });
})

$('.edit').click(function(){
    $editTr = $(this).closest("tr");
    var id = $editTr.data('user_id');
    layer_font = layer.open({
        type: 2,
        title: '修改用户',
        shadeClose: true,
        shade: 0.8,
        area: ['600px', '90%'],
        content: '{:url("edit")}?id='+id, //iframe的url
    });
})

function editSuccess(data) {
    layer.close(layer_font);
    $editTr.find("td:eq(2)").html(data.username+'<br />'+data.phone);
    $editTr.find("td:eq(3)").html('名称：'+data.shop_name+'<br>负责人：'+data.shop_owner+'<br>地址：'+data.shop_address);
    $editTr.find("td:eq(4)").html(data.sc_name);
    layer.msg('修改成功！', {icon: 1});
}
//切换排序
$('.select_sort').click(function(){
    var select_sort = $(this).data('select_sort');
    var sort = $(this).data('sort');
    if(sort=='desc'){
        $('.sort_status').val('asc');
    }else{
        $('.sort_status').val('desc');
    }
    $('.sort').val(select_sort+$('.sort_status').val());

    $('#froms').submit();
})

$(document).on('change','.quciksubmit',function(){
	$('#froms').submit();
});
</script>